#include<bits/stdc++.h>
#define lowbit(x) ((x)&-(x))
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
long long f[1<<15|1];
int cnt[1<<15|1],val[1<<15|1];
bool b[1<<15|1];
int n,k;
int a[21];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("diyiti.in","r",stdin);
	freopen("diyiti.out","w",stdout);
	cin >> n >> k;
	for(int i = 0;i < n;i++)
		cin >> a[i];
	sort(a,a + n);
	for(int S = 1;S < (1 << n);S++)
	{
		cnt[S] = cnt[S ^ lowbit(S)] + 1;
		if(cnt[S] == n / k)
		{
			int lst = -1,mn = INT_MAX;bool flag = 1;
			for(int i = 0;i < n;i++) if(S & (1 << i))
			{
				if(lst == a[i])
					flag = 0;
				if(lst == -1)
					mn = a[i];
				lst = a[i];
			}
			if(flag)
				val[S] = lst - mn,b[S] = 1;
		}
	}
	memset(f,0x3f,sizeof(f));
	f[0] = 0;
	for(int S = 0;S < (1 << n);S++)
		for(int T = S;T;(--T) &= S) if(b[T])
			f[S] = min(f[S],f[S ^ T] + val[T]);
	cout << (f[(1 << n) - 1] == inf ? -1 : f[(1 << n) - 1]);
	return 0;
}
//我有一个绝妙的做法，但是时间太紧，写不完了